package com.qf.openapi.web.master.utils;

import javafx.concurrent.Task;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Slf4j
public class FileAppender<T> {

    private String filePath = "L:\\2202\\idea\\xm\\ssm2202\\src\\main\\webapp\\upload\\";

    private BufferedWriter getBuf() throws IOException {
        String path = filePath + getFileName();
        File file = new File(path);
        if (!file.exists()) {
            file.createNewFile();
        }
        return new BufferedWriter(new FileWriter(file, true));
    }

    public static String getFileName() {
        return UUID.randomUUID() + ".xls";
    }

    public void appendListtoFile(List<String> list) throws Exception {

        BufferedWriter buf = getBuf();
        for (String str : list) {
            buf.write(str);
            buf.newLine();
        }
        log.debug("添加的对象为={}", list.toString());
        buf.close();

    }
}

